<?

define("_BASE_CURRENCY"                   , "CURRENCY");
define("_BASE_LANGUAGE"                   , "LANGUAGE");
define("_BASE_METHOD"                     , "METHOD");

$thisMdl        = "UTILITIES";

$stlEntry       = " size='11'
                    maxlength='10' ";

$lstMenu        = array("Base Language",
                        "Base Currency",
                        "Base Level",
                        "Base Method");

$srcDbMstCurrency   = "MST_CURRENCY";
$srcDbGrlSetting    = "GRL_SETTING";
$srcDbMstLevelD     = "MST_LEVELD";
$srcDbMstMethod     = "MST_METHOD";
$srcDbMstSequence   = "MST_SEQUENCE";

$GHtml  = new CGHtml;
$GJs    = new CGJavascript;
$Misc   = new Misc;

$CFetchers = new GlobalFetchers;
$CHandlers = new GlobalHandlers;

//lets init the first table
echo  "<br/><br/><br/><br/><br/>\n".

			"<table border='1' align='center' class='dedeq'>\n".
			"<th> Desc  </th>\n".
			"<th> Value </th>\n".
			"<form action=# method=post>\n";

//connect to db to retrieve data with system period as the range
$COracle = new oracleDb;
$COracle->init($_SESSION["ORCL"],
               $_SESSION["OPASS"],
               $_SESSION["SID"],
               _NO_COMMENT);

if ($COracle->connect()) {

  $CMonthly = new CMonthlyUpdate($COracle);

  /**
  * Base Language init
  *
  */
  $lstLanguage = array("English");

  $propLanguange = " onChange=' ".
                              "chgCurValue(\"langEnt\"); ".
                              "' ";
  echo  "<tr>\n".
          "<td> Base Language </td>".
          "<td> ".formDropDown("langEnt",
                               $_POST["langEnt"],
                               $lstLanguage,
                               $propLanguage)." </td>\n".
        "</tr>\n";

	/**
  * Base Currency init
  *
  */
  fetchLstCurrency($COracle,
                   $srcDbMstCurrency,
                   $lstCurrency);

  $propCurrency = " onChange=' ".
                             "chgCurValue(\"currency\",
                                          \"crrEnt\"); ".
                             "' ";

  if($_SESSION["baseCurrency"]){

    $_POST["crrEnt"] = $_SESSION["baseCurrency"];
  }else{

    $CFetchers->fetchGrlSetting($COracle,
                                _BASE_CURRENCY,
                                $srcDbGrlSetting,
                                $_POST["crrEnt"]);

    $_SESSION["baseCurrency"] = $_POST["crrEnt"];
  }

  echo  "<tr>\n".
          "<td> Base Currency </td>".
          "<td> ".formDropDown("crrEnt",
                               $_POST["crrEnt"],
                               $lstCurrency,
                               $propCurrency)." </td>\n".
        "</tr>\n";

  /**
  * Base LevelD init
  *
  */
  fetchLstLevelD($COracle,
                 $srcDbMstLevelD,
                 $lstLevelD);

  fetchSelLevelD($COracle,
                 $srcDbMstLevelD,
                 $_POST["lvlDEnt"]);

  $propLevelD = " onChange=' ".
                           "chgCurValue(\"levelD\",
                                        \"lvlDEnt\"); ".
                           "' ";
  echo  "<tr>\n".
          "<td> Base LevelD </td>".
          "<td> ".formDropDown("lvlDEnt",
                               $_POST["lvlDEnt"],
                               $lstLevelD,
                               $propLevelD)." </td>\n".
        "</tr>\n";

  /**
  * Base Method init
  *
  */
  fetchLstMethod($COracle,
                 $srcDbMstMethod,
                 $lstMethod);

  fetchSelMethod($COracle,
                 $srcDbMstMethod,
                 $_POST["methodEnt"]);

  $propMethod = " onChange=' ".
                           "chgCurValue(\"method\",
                                        \"methodEnt\"); ".
                           "' ";
  echo  "<tr>\n".
          "<td> Base Method </td>".
          "<td> ".formDropDown("methodEnt",
                               $_POST["methodEnt"],
                               $lstMethod,
                               $propMethod)." </td>\n".
        "</tr>\n";

  /**
  * Reset all sequences
  *
  */

  /**
  * buggy, rstSeqEnt supposed to be
  * the latest date of entry of sequence
  *
  */
  $_POST["rstSeqEnt"] = $_SESSION["sysPeriode"];

  $propRstSequence = $GJs->jsOnClick("resetPeriode(\"rstSeqEnt\");");

  echo  "<tr>\n".
          "<td> Current Periode</td>".
          "<td> ".formInput( "rstSeqEnt",
                             $_POST["rstSeqEnt"],
                             $propNull . $stlEntry)."
                <a href=# >
                <img src    = '/ecs/images/modify.png'
                     width  = 15
                     height = 15
                     alt    = 'Modify'
                     ".$propRstSequence." > </a> </td>\n".
        "</tr>\n";

  /**
  * buggy, paramater shouldn't sysPeriode
  * but rstSeqEnt which if this page newly load
  * then rstSeqEnt is the latest date of entry of sequence
  *
  */
  $CMonthly->resetSequence($_SESSION["sysPeriode"]);

  $COracle->commit();

  /**
  * BackUp sequences
  *
  */
  echo  "<tr>\n".
          "<td> Backup Sequences </td>".
          "<td> &nbsp &nbsp
                ".$GHtml->actionIcon("miniBackupSeq",
                                     "miniBackupSeq",
                                     20,
                                     20,
                                     "/ecs/images/Box_Input.png",
                                     "miniBackupSeq()")."

                &nbsp &nbsp
                ".$GHtml->actionIcon("miniReloadSeq",
                                     "miniReloadSeq",
                                     20,
                                     20,
                                     "/ecs/images/Box_Output.png",
                                     "miniReloadSeq()")." </td>\n".
        "</tr>\n";

	echo  "</table>\n".
				"<br/>\n".
				"</form>\n";

	$COracle->dc();
}else{

  $Misc->usrDie("DB connection failed");
}

session_commit();

?>